<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Article Comments</title>
</head>
<body>
    <h1>Comments for Article</h1>

    <!-- 添加评论表单 -->
    <h2>添加评论</h2>
    <form action="#" th:action="@{/comments/add/{articleId}(articleId=${articleId})}" method="post">
        <div>
            <label for="author">作者:</label>
            <input type="text" id="author" name="author" required>
        </div>
        <div>
            <label for="content">内容:</label>
            <textarea id="content" name="content" rows="4" required></textarea>
        </div>
        <button type="submit">添加评论</button>
    </form>

    <!-- 评论列表 -->
    <table border="1">
        <tr>
            <th>ID</th>
            <th>作者</th>
            <th>内容</th>
            <th>操作</th>
        </tr>
        <tr th:each="comment : ${comments}">
            <td th:text="${comment.id}"></td>
            <td th:text="${comment.author}"></td>
            <td th:text="${comment.content}"></td>
            <td>
                <a th:href="@{/comments/edit/{id}(id=${comment.id})}">编辑</a> |
                <a th:href="@{/comments/delete/{id}(id=${comment.id})}" onclick="return confirm('确定要删除吗？')">删除</a>
            </td>
        </tr>
    </table>
</body>
</html>